//package com.funny.stock.trade.service;
//
//import com.funny.stock.base.service.BaseCrudServiceV2;
//import com.funny.stock.base.util.PageUtil;
//import com.funny.stock.trade.dao.pojo.ComposeAssetsDO;
//import com.funny.stock.trade.dao.repo.ComposeAssetsRepo;
//import com.funny.stock.trade.vo.ComposeAssetsVO;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
//import org.springframework.data.jpa.domain.Specification;
//import org.springframework.data.jpa.repository.JpaRepository;
//import org.springframework.stereotype.Service;
//
//import javax.persistence.criteria.CriteriaBuilder;
//import javax.persistence.criteria.CriteriaQuery;
//import javax.persistence.criteria.Predicate;
//import javax.persistence.criteria.Root;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @Description
// * @Author  pengl
// * @Date 2020-05-17
// */
//
//@Service
//public class ComposeAssetsService extends BaseCrudServiceV2<ComposeAssetsVO,ComposeAssetsDO,Long> {
//
//	@Autowired
//	ComposeAssetsRepo repository;
//
//	protected JpaRepository<ComposeAssetsDO, Long> setupJpaRepository() {
//		return repository;
//	}
//
//	@Override
//	protected Class<ComposeAssetsDO> getDOClass() {
//		return ComposeAssetsDO.class;
//	}
//
//	@Override
//	protected Class<ComposeAssetsVO> getVOClass() {
//		return ComposeAssetsVO.class;
//	}
//
//	public ComposeAssetsVO findByComposeId(Long composeId){
//		return  convertVO(repository.findByComposeId(composeId));
//	}
//
//	public ComposeAssetsVO findByCreateIdAndId(Long createId, Long id){
//		return convertVO(repository.findByUserIdAndId(createId,id));
//	}
//
//	public ComposeAssetsVO findByUserIdAndComposeId(Long createId, Long id){
//		return convertVO(repository.findByUserIdAndComposeId(createId,id));
//	}
//
//	public Page<ComposeAssetsVO> queryByCondition(ComposeAssetsVO queryVO, Integer pageNumber, Integer pageSize){
//		Specification specification = new Specification() {
//			@Override
//			public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) {
//				List<Predicate> predicates = new ArrayList<>();
//
//				if(null != queryVO.getComposeId()){
//					predicates.add(criteriaBuilder.equal(root.get("composeId"), queryVO.getComposeId()));
//				}
//
//				if(null != queryVO.getUserId()){
//					predicates.add(criteriaBuilder.equal(root.get("userId"), queryVO.getUserId()));
//				}
//
//				if(null != queryVO.getUpdateTime()){
//					predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("updateTime"), queryVO.getUpdateTime()));
//				}
//
//				return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
//			}
//		};
//		PageRequest pageRequest = PageUtil.buildPageRequest(pageNumber, pageSize);
//		return repository.findAll(specification,pageRequest);
//	}
//
//	public boolean canBuy(ComposeAssetsVO assetsVO, BigDecimal tradePrice, Long tradeNumber){
//		BigDecimal tradeMoney = tradePrice.multiply(BigDecimal.valueOf(tradeNumber));
//		return assetsVO.getCash().compareTo(tradeMoney) >= 0;
//	}
//}
